package com.hyf.meterialdesign.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

/**
 * Created by HeYongFeng on 2017/4/6.
 */

public class SimpleFragment extends Fragment {
    private static final String BUNDLE_URL = "BUNDLE_URL";
    private static final String BUNDLE_FIT= "BUNDLE_FIT";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        String imageUrl = bundle.getString(BUNDLE_URL);
        boolean isFitsSystemwindow = bundle.getBoolean(BUNDLE_FIT);
        ImageView imageView = new ImageView(getContext());
        Glide.with(getContext()).load(imageUrl).into(imageView);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        if (isFitsSystemwindow) {
            imageView.setFitsSystemWindows(true);
        }
        return imageView;
    }

    public static SimpleFragment newInstance(String imageUrl,boolean isFitsSystemwindow){
        SimpleFragment simpleFragment = new SimpleFragment();
        Bundle bundle = new Bundle();
        bundle.putString(BUNDLE_URL,imageUrl);
        bundle.putBoolean(BUNDLE_FIT,isFitsSystemwindow);
        simpleFragment.setArguments(bundle);
        return simpleFragment;
    }
}
